import pop from '../utils/pop';
import env from '../config/env';

const ticket = localStorage.ticket;
const prefix = env.gwApiPrefix;
const errorHandler = error => {
	pop.error("加载数据失败！");
	console.log(error);
}

export default {
	getQuestionsInfo(facadeId) {
		return axios.get(`${prefix}/api/zsapi/exam/facade/paperFacades/${facadeId}/questions?ticket=${ticket}`).catch(errorHandler);
	},
	getQuestion(id) {
		return axios.get(`${prefix}/api/zsapi/exam/questions/${id}?ticket=${ticket}`).catch(errorHandler);
	},
	saveQuestion(model) {
		return axios.post(`${prefix}/api/zsapi/exam/questions?ticket=${ticket}`, {
			id: model.id,
			facadeId: model.facadeId,
			awser: model.awser instanceof Array ? model.awser.join(',') : model.awser,
			awserOption: JSON.stringify(model.awserOption),
			questionType: model.questionType,
			content: model.content,
		});
	},
	donePaper(facadeId) {
		return axios.post(`${prefix}/api/zsapi/exam/facade/paperFacades/updatePaper?id=${facadeId}&ticket=${ticket}`);
	},
	getPaperInfo(facadeId) {
		return axios.get(`${prefix}/api/zsapi/exam/facade/paperFacades/${facadeId}?ticket=${ticket}`).catch(errorHandler);
	},
	deletePaper(facadeId) {
		return axios.post(`${prefix}/api`)
	}
}